package com.ruix.app.manager;

import android.content.SharedPreferences;
import android.text.TextUtils;

import com.ruix.app.RuiApplication;

/**
 * Created by hadexs on 2017/4/23.
 */

public class ClientInfo {


    public final static String spName = "clientInfo";
    private static final String KEY_UID = "key_uid";//
    private final static String Key_isFirstStarted = "Key_isFirstStarted";// 是否第一次启动
    private static final String KEY_PUSH_TOKEN = "Key_pushToken"; // 推送token
    private static final String KEY_UPLOAD_DEBUGINFO = "key_upload_debuginfo";
    private static final String KEY_UIDES_LOGIN = "uid_login";
    private static final String KEY_LAST_APP_NAME = "last_app_name";//下载app文件名称  如果升级文件下载完成 把文件名称缓存起来

    private static final String KEY_FEEDBACK_CLASS_ID = "feedback_class_id";
    private static final String KEY_APP_UPGRADE_TIP = "app_upgrade_tip";

    public static SharedPreferences getSp() {
        return RuiApplication.getAppContext().getSharedPreferences(spName, 0);//
    }


    /**
     * 保存个推推送token
     *
     * @param pushToken
     */
    public static void setPushToken(String pushToken) {
        getSp().edit().putString(KEY_PUSH_TOKEN, pushToken).commit();
    }

    /**
     * 获取个推 推送token
     *
     * @return
     */
    public static String getPushToken() {
        return getSp().getString(KEY_PUSH_TOKEN, "");
    }

    /**
     * 获取当前登录用户的uid 当返回为空时代表没有用户登录过
     *
     * @return
     */
    public static String getCurrentUid() {
        return getSp().getString(KEY_UID, "");
    }

    /**
     * 保存当前登录用的uid
     * 免登录
     *
     * @param uid
     */
    public static void setCurrentUid(String uid) {
        getSp().edit().putString(KEY_UID, uid).commit();
        addLoginUids(uid);
    }


    /**
     * 获取在app上登录过的所有用户id
     * 用户切换
     *
     * @return
     */
    public static String getUids() {
        return getSp().getString(KEY_UIDES_LOGIN, "");
    }

    /**
     * 保存登录过的用户id
     *
     * @param uid
     */
    public static void addLoginUids(String uid) {
        if (!TextUtils.isEmpty(uid)) {
            String uids = getUids();
            if (!uids.contains(uid)) {
                uids += uid + ",";
                getSp().edit().putString(KEY_UIDES_LOGIN, uids).commit();
            }
        }
    }


    /**
     * 是否第一次启动app  使用场景 引导页
     *
     * @param version app versioncode
     * @return
     */
    public static boolean isFirstLauncherApp(String version) {
        return getSp().getBoolean(Key_isFirstStarted + version, true);
    }


    /**
     * 设置第一次启动完成
     *
     * @param version
     */
    public static void setFirstLaunchedApp(String version) {
        getSp().edit().putBoolean(Key_isFirstStarted + version, false).commit();
    }


    //更新app文件名称  标记下载成功
    public static void setAppFileName(String name) {
        getSp().edit().putString(KEY_LAST_APP_NAME, name).commit();
    }

    //更新app文件名称
    public static String getAppFileName() {
        return getSp().getString(KEY_LAST_APP_NAME, "");
    }


    //意见反馈圈子id
    public static void setFeedbackClassID(String name) {
        getSp().edit().putString(KEY_FEEDBACK_CLASS_ID, name).commit();
    }

    //
    public static String getFeedbackClassID() {
        return getSp().getString(KEY_FEEDBACK_CLASS_ID, "");
    }


    //意见反馈圈子id
    public static void setHintAppUpgrae(String version) {
        getSp().edit().putBoolean(KEY_APP_UPGRADE_TIP + version, true).commit();
    }

    //
    public static boolean isHintAppUpgrae(String version) {
        return getSp().getBoolean(KEY_APP_UPGRADE_TIP + version, false);
    }



}
